package com.test.PSO;

import com.test.BRBInference.BRBInference;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class test {
    public static void main(String[] args) throws IOException {


        File dataFile = new File("F:\\JAVA\\Project\\Java_web\\data_2.txt");
        File modelFile = new File("F:\\JAVA\\Project\\Java_web\\model_2.txt");
        ArrayList<Double> uscale = new ArrayList<Double>();
        uscale.add(-15.0);
        uscale.add(-12.0);
        uscale.add(-9.0);
        uscale.add(-6.0);
        uscale.add(-3.0);

        BRBInference BRB = new BRBInference(dataFile, modelFile, uscale);
        BRB.Load();
        BRB.attr_identify();
        BRB.fuse();
        BRB.contr_w_beta();
        BRB.data_Handle();
        ArrayList<Double> inference_result = BRBInference.abs(BRB.getInference_Result());
        ArrayList<ArrayList<Double>> dataArray = BRB.getDataArray();
        ArrayList<ArrayList<Integer>> attrArray = BRB.getData_attr();
        ArrayList<ArrayList<Double>> modelArray = BRB.getModelArray();

        for (int i = 0; i < attrArray.size(); ++i) {
            for (int j = 0; j < attrArray.get(i).size(); ++j) {
                attrArray.get(i).set(j, attrArray.get(i).get(j) - 1);
            }
        }

        ArrayList<ArrayList<Double>> optimal_data = new ArrayList<>();
        ArrayList<Double> optimal_Result = new ArrayList<>();
        ArrayList<Double> optimal_Result2 = new ArrayList<>();
        for (int num = 0; num < dataArray.size(); ++num) {
            ArrayList<Double> data = dataArray.get(num);
            ArrayList<Integer> attr = attrArray.get(num);

            PSO pso = new PSO(uscale, data, modelArray, attr);
            pso.Init();
            pso.Process();

            optimal_Result.add(pso.getZbestfitness());
            optimal_Result2.add(inference_result.get(num)-pso.getZbestfitness());

            pso.getZbest().remove(pso.getZbest().size()-1);
            optimal_data.add(pso.getZbest());
        }
        System.out.println();
    }

}
